alias which alias !\$ \| /usr/local/bin/which -i !\*
in csh, or
alias which eval alias '\"\$$#\" |' \ /usr/local/bin/which -i '${1+"$@"}'
in shells which are supersets of sh and which know aliases. If your shell has shell functions, you can use the following function:
which() { eval last=\"\$$#\" set | sed -n "/^$last(){$/,/^}$/p" | /usr/local/bin/which -i ${1+"$@"} }
If the -a (all) flag is given, which will not stop after the first `match', but search for all occurrences of command in the user's PATH. The -- flag can be used to end the list of options: the next argument (if present) will be taken as command, even if it starts with a `-'. which [-i] [-a] [--] without further arguments prints the user's PATH broken up into its components, one per line.
This new version of the which command is not a csh script. Being an executable it is much faster, and not sourcing .cshrc it gives a true picture of one's aliases. Furthermore it will give the correct answers even if:
% alias which alias !$ | /usr/local/bin/which -i !* % which which which alias !$ | /usr/local/bin/which -i !* % which -a which which alias !$ | /usr/local/bin/which -i !* /usr/local/bin/which /usr/ucb/which %